var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("GlobalParams"),
    a = cc._decorator,
    i = a.ccclass,
    r =
        (a.property,
        (function () {
            function e() {
                (this.sounds = {}),
                    (this.fight_sounds = {}),
                    (this.enabled = !0),
                    (this.music = ""),
                    (this._sfxVolume = -1),
                    (this.musicVolume = 0.5);
            }
            var t;
            return (
                (t = e),
                (e.getInstance = function () {
                    return this.instance || (this.instance = new t()), this.instance;
                }),
                (e.prototype.addSound = function (e, t) {
                    this.sounds[e] = t;
                }),
                (e.prototype.addFightSound = function (e, t) {
                    this.fight_sounds[e] = t;
                }),
                (e.prototype.playFx = function (e, t) {
                    if ((void 0 === t && (t = !1), this.enabled)) {
                        var o;
                        o = n.GlobalParams.gameSound.value ? 1 : 0;
                        var a = 0;
                        return (
                            this.sounds[e]
                                ? (a = cc.audioEngine.play(this.sounds[e], t, o))
                                : this.fight_sounds[e] && (a = cc.audioEngine.play(this.fight_sounds[e], t, o)),
                            a
                        );
                    }
                }),
                (e.prototype.playMusic = function (e) {
                    (this.music = e),
                        n.GlobalParams.gameMusic.value &&
                            this.enabled &&
                            (this._sfxVolume && cc.audioEngine.stop(t.getInstance()._sfxVolume),
                            this.sounds[e]
                                ? (this._sfxVolume = cc.audioEngine.play(this.sounds[e], !0, this.musicVolume))
                                : (this._sfxVolume = cc.audioEngine.play(this.fight_sounds[e], !0, this.musicVolume)));
                }),
                (e.prototype.setMusicVolume = function (e) {
                    this._sfxVolume > -1 && cc.audioEngine.setVolume(this._sfxVolume, e), (this.musicVolume = e);
                }),
                (e.prototype.setEnabled = function (e) {
                    (this.enabled = e), this.enabled ? this.playMusic(this.music) : cc.audioEngine.stopAll();
                }),
                (e.prototype.getEnable = function () {
                    return this.enabled;
                }),
                (e.loadSounds = function (e) {
                    cc.loader.loadResDir("sound", cc.AudioClip, function (o, n) {
                        for (var a = 0; a < n.length; a++) t.getInstance().addSound(n[a].name, n[a]);
                        e();
                    });
                }),
                (e.ButtonSound = function () {
                    t.getInstance().playFx(n.GlobalParams.btn_sound);
                }),
                (e.playGameBGM = function () {
                    t.stopMusic(), t.getInstance().playMusic(n.GlobalParams.gameMusicName);
                }),
                (e.stopMusic = function () {
                    cc.audioEngine.stop(t.getInstance()._sfxVolume);
                }),
                (t = __decorate([i], e))
            );
        })());
o.default = r;
